package com.xgr.wonderful.utils;

import com.xgr.wonderful.constant.Constant;
import com.xgr.wonderful.entity.User;

import android.content.Context;
import android.telephony.TelephonyManager;

import com.google.gson.Gson;

public class SettingUtils {
	
	public static final void SaveUserJson(Context context, String json) {
		Sputil sputil = new Sputil(context, Constant.BASIC_PRE_NAME);
		sputil.setValue(Constant.LOCAL_USER_JSON, json);
	}

	public static final User GetUserFromJson(Context context) {
		Sputil sputil = new Sputil(context, Constant.BASIC_PRE_NAME);
		String str = null;
		User user = null;
		str = sputil.getValue(Constant.LOCAL_USER_JSON, null);

		if (str != null)
			user = new Gson().fromJson(str, User.class);
		return user;
	}

	public static final String getDeviceId(Context context) {
		TelephonyManager tm = (TelephonyManager) context
				.getSystemService(Context.TELEPHONY_SERVICE);
		if (tm.getDeviceId() != null){
			return tm.getDeviceId() ; //deviceid 
		}else {
			return tm.getLine1Number() ; // tele number 
		}
	}
}
